<?header('Content-type: application/xhtml+xml');?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <title>Quicklog</title>
    <link rel="alternate" type="application/rss+xml" title="RSS" href="rss.xml" />
	<link rel="stylesheet" type="text/css" href="css/style.css" />
	<link rel="stylesheet" type="text/css" href="css/reset.css" />
</head>
<body>
	<div class="container">
	    <h1><img src="img/logo.png" alt="Quicklog" title="Quicklog" /></h1>
	    <h2><img src="img/archives.png" alt="Archives" title="Archives" /></h2>
		<div class="menu"><a href="./">&larr;Home</a> | <a href="./about.php">About</a> | Archives</div>
		<div id="entries">
		<?php
		include_once 'config.php';
		include_once 'time.php';
		$i = 0;
		foreach(file($file) as $key => $value){
			$i++;
			$line = explode('|', $value);
			$archive[$line[0]] = $line[1];
		}
		$num_entries = $i;
		$i = 0;
		$page = isset($_GET['page']) ? $_GET['page'] : 1;
		$page = $page-1;
		$min = $page*10;
		$max = $page+1;
		$max = $max*10;
		foreach($archive as $time => $entry){
			$i++;
			if($line != '' && $i>$min && $i<$max){
				$time = timeDiff($time, array('precision' => 'minute'));
				echo '
				<div class="first entry">
				<span class="time">'.$time.':</span><br /> 
				'.rtrim($entry).'
				</div>';
			}
		}
		?>
		</div>
		<?php
			$num_pages = ceil(round($num_entries/10, 1));
			$i = $num_pages;
			$num = 1;
			$page = isset($_GET['page']) ? $_GET['page'] : 1;
			$nxt = $page+1;
			$prv = $page-1;
			
		?>
		<?=$num_pages?> Pages, <?=$num_entries?> Entries<br />
		<?php 
		if($page == 1){
			echo ' '.$page.' <a href="./archive.php?page='.$nxt.'">'.$nxt.' &gt;&gt;</a>';
		}
		elseif($page == $num_pages){
			echo '<a href="./archive.php?page='.$prv.'">&lt;&lt; '.$prv.'</a> '.$page.' ';
		}
		else{
			echo '<a href="./archive.php?page='.$prv.'">&lt;&lt; '.$prv.'</a> '.$page.' <a href="./archive.php?page='.$nxt.'">'.$nxt.' &gt;&gt;</a>';
		}
		/*
		while(0<$i): 
			if($num != $page){
				echo '<a href="./archive.php?page='.$num.'">'.$num.'</a> '; 
			}
			else{
				echo ' '.$num.' ';
			}
			$i--;
			$num++;
		endwhile;
		*/
		?>
	</div>
	<p id="valid">
		<a href="http://validator.w3.org/check?uri=referer">
			<img src="http://www.w3.org/Icons/valid-xhtml11-blue" alt="Valid XHTML 1.1" height="31" width="88" />
		</a>
	</p>
</body>
</html>